<?php
/*
 *      osmetadictionaryedit.php
 *      
 *      Copyright 2011 ViRak <vetalrakitin@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/oscomponent.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/osbutton.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/osedit.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/oscombobox.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/osdefaultlistdictionaryedit.php");

class osdictionariesedit extends oscomponent {

	private $cbdictionaries;
	private $dictionaries;
	private $dictionaryedit;

	
	function __construct($parent) {
		parent::__construct($parent);
	
		$this->cbdictionaries = new oscombobox(0);
		$this->cbdictionaries->setevent($this, "onchange", "cbdictionariesonchange");
		$this->dictionaryedit = new osdefaultlistdictionaryedit(0);
		
		//$this->metadictionaryfieldedit = new osmetadictionaryfieldedit(0);
	}
	
	function cbdictionariesonchange($value) {
		//$this->dictionary = $this->dictionaries->byuuid($value);
		//$this->initialize();
		$this->dictionaryedit->meta = $this->dictionaries->byuuid($value);
		$this->update();
	}

	function __set($name, $value) {
		switch ($name) {
			case "dictionaries":{
				if ($value == null) {
					$this->dictionaries = $value;
					$this->cbdictionaries->deleteallitems();
					//$this->hide();
				} elseif (get_class($value) == "osmetadictionaries") {
					$this->dictionaries = $value;
					$this->cbdictionaries->deleteallitems();
					foreach ($this->dictionaries->getall() as $dic) {
						$this->cbdictionaries->additem($dic->uuid,$dic->name);
					}
					$this->dictionaryedit->meta = $this->dictionaries->byuuid($this->cbdictionaries->selecteditem());
					//$this->dictionary = $this->dictionaries->byuuid($this->cbdictionaries->selecteditem());
					//$this->initialize();
					//$this->show();
				}
				break;
			}
		}
	}
	
	function get() {
		$ret = "<div id=".$this->uuid;
		$ret .= $this->visible?"":" hidden";
		$ret .= ">";
		$ret .= "<fieldset><legend>Справочники</legend>";
		$ret .= $this->cbdictionaries->get();
		
		$ret .= $this->dictionaryedit->get();
		
		//$ret .= "<pre>".print_r($this,1)."</pre>";
/*
		if ($this->dictionary) {
			$ret .= "<fieldset><legend>Свойства</legend>";
			$ret .= $this->eduuid->get()."<br>";
			$ret .= $this->edname->get()."<br>";
			$ret .= "<fieldset><legend>Поля</legend>";
			$ret .= $this->metadictionaryfieldedit->get();
			$ret .= "</fieldset>";
			$ret .= "<fieldset><legend>Таблицы</legend>";
			$ret .= $this->cbtabulars->get().$this->bttabularadd->get().$this->bttabulardelete->get()."<br></fieldset>";
			$ret .= "</fieldset>";
		}
*/
		$ret .= "</fieldset></div>";
		return $ret;
	}
}
?>
